//
//  ContentView.swift
//  Fitness
//
//  Created by duanwenpu on 2021/9/9.
//

import SwiftUI

struct helloModel: Identifiable {
    var id:Int
    var name: String
    
}
 var models: [helloModel] = [helloModel(id: 1, name: "hellOne")]

struct ContentView: View {
    @State var isLinkActive = false
    @State var pushActive = false
    @State private var selection: String? = nil
    @State var temp = false
    @State var handledWeekTraining: Array<EveryDayTrainingModel> = WeekTraining
    var body: some View {
        TabView{
            NavigationView {
                List{
               
               ForEach(handledWeekTraining) {perTraining in
                   
                   NavigationLink(destination: EditTrainingContentView(currentTitle: perTraining.whatDay, handledWeekTraining: $handledWeekTraining, edit:false, currentDayTraining: perTraining, pushActive: $pushActive ),tag: String(perTraining.id), selection:$selection, label: {
                       Button(action: {
                           self.selection = String(perTraining.id)
                       }, label: {
                           Text(String(perTraining.whatDay))
                       })
                   })
               }.onDelete { indexSet in
              

                   deleteAction(indexSet)
               }
                }
               .foregroundColor(.red)
               .navigationTitle("训练计划")
               .navigationBarItems(trailing: NavigationLink(
                                       destination: EditTrainingContentView(currentTitle: "添加计划", handledWeekTraining: $handledWeekTraining, edit: true, currentDayTraining: EveryDayTrainingModel(id: (handledWeekTraining.count + 1), whatDay: "星期一", trainingGroupArray: []), pushActive: $pushActive),
                                       isActive: $isLinkActive,
                                       label: {
                                           Button(action: {
                                               getdata()
                                               self.isLinkActive = true
                                           }, label: {
                                               Text("添加计划")
                                           })
                                       }))
           }
                .tabItem {
                    
                    Image(systemName: "signature")
                    Text("First")
                }
            Text("The First Tab")
                    .tabItem {
                        
                        Image(systemName: "heart.fill")
                        Text("First")
                    }
                Text("Another Tab")
                    .tabItem {
                        Image(systemName: "2.square.fill")
                        Text("Second")
                    }
                Text("The Last Tab")
                    .tabItem {
                        Image(systemName: "3.square.fill")
                        Text("Third")
                    }
            

            
        }

    }
    func deleteAction(_ index: IndexSet)  {
//        let model =  handledWeekTraining[index.startIndex] as EveryDayTrainingModel
        
        handledWeekTraining.remove(atOffsets: index)
    }

}



struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
